<template>
  <div class="docker">
    <div
      v-for="(item, index) in pageList.data"
      :key="index"
      :class="{ 'docker__item--active': index == activeIndex }"
      class="docker__item"
      @click="
        () => {
          handleRouter(index, item);
        }
      "
    >
      <div class="iconfont" v-html="item.icon"></div>
      <p class="dock__title">{{ item.txt }}</p>
    </div>
  </div>
</template>

<script>
import { reactive, ref } from "vue";
import { useRouter } from "vue-router";
export default {
  name: "docker",
  props: ["activeIndex"],
  setup() {
    let pageList = reactive({
      data: [
        {
          icon: "&#xe904;",
          txt: "首页",
          name: "",
        },
        {
          icon: "&#xe826;",
          txt: "购物车",
          name: "cart",
        },
        {
          icon: "&#xe833;",
          txt: "订单",
          name: "orderList",
        },
        {
          icon: "&#xe78b;",
          txt: "我的",
          name: "my",
        },
      ],
    });
    const router = useRouter();
    const handleRouter = (index, item) => {
      router.push(`/${item.name}`);
    };
    return { pageList, handleRouter };
  },
};
</script>

<style scoped lang="scss">
@import "@/styles/variables.scss";
.docker {
  box-sizing: border-box;
  position: absolute;
  left: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  width: 100%;
  height: 0.5rem;
  border-top: 1px solid #f1f1f1;
  background-color: #fff;
  padding: 0 0.18rem;
  a {
    color: $content-color;
  }
}
.docker__item {
  box-sizing: border-box;
  padding: 0.05rem 0 0.05rem 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  .iconfont {
    font-size: 0.2rem;
  }
  &--active {
    color: #1fa4fc;
  }
  .dock__title {
    font-size: 0.1rem;
  }
}
</style>
